<template>
    <div>
        <van-nav-bar title="标题" left-text="返回" left-arrow @click-left="onClickLeft" />
        <van-form @submit="onSubmit">
            <van-cell-group inset>
                <van-field v-model="username" name="username" label="账号" placeholder="请输入账号"
                    :rules="[{ required: true, message: '请输入账号' }]" />
                <van-field v-model="password" type="password" name="password" label="密码" placeholder="请输入密码"
                    :rules="[{ required: true, message: '请输入密码' }]" />
            </van-cell-group>
            <div style="margin: 16px;">
                <van-button round block type="primary" native-type="submit">
                    登录
                </van-button>
            </div>
        </van-form>
    </div>
</template>

<script setup>
import { ref } from 'vue';
import { loginApi } from '@/api/api';
import router from '@/router';
let onClickLeft=()=>{
    router.push('/zc')
}
const username = ref('');
    const password = ref('');
    let onSubmit=()=>{
        loginApi(username.value,password.value).then(res=>{
            console.log('登录',res)
            router.push('/sy')
            localStorage.getItem('token',res.data.data.token);
            localStorage.getItem('username',res.data.data.username);

        })
    }
</script>

<style lang="scss" scoped></style>